package cloud.misiro.spring.cloud.registry;

import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;

public class MiniAutoServiceRegistration extends AbstractAutoServiceRegistration<Registration> {

    private final MiniRegistration miniRegistration;

    protected MiniAutoServiceRegistration(ServiceRegistry<Registration> serviceRegistry, MiniRegistration miniRegistration) {
        super(serviceRegistry, null);
        this.miniRegistration = miniRegistration;
    }

    @SuppressWarnings("deprecation")
    @Override
    protected Registration getRegistration() {
        if (miniRegistration.getPort() < 0) {
            miniRegistration.setPort(this.getPort().get());
        }
        return miniRegistration;
    }

    @Override
    protected Object getConfiguration() {
        return miniRegistration.getMiniDiscoveryProperties();
    }

    @Override
    protected boolean isEnabled() {
        return true;
    }

    @Override
    protected Registration getManagementRegistration() {
        return null;
    }
}
